#include <QSet>
#include "htmlattributelist.h"
#include "htmlattribute.h"

HtmlAttributeList::HtmlAttributeList(const YYLTYPE& loc)
        : Node(loc)
{
}

QList<HtmlAttribute*> HtmlAttributeList::attributes() const
{
    QList<HtmlAttribute*> result;

    Node* p = firstChild();
    while( p )
    {
        HtmlAttribute* a = dynamic_cast<HtmlAttribute*>(p);
        if ( a )
            result.append(a);
        p = p->nextSibling();
    }

    return result;
}

void HtmlAttributeList::resolveAll()
{
    this->Node::resolveAll();

    QSet<QString> names;
    Node* p = this->firstChild();
    while( p )
    {
        HtmlAttribute* a = dynamic_cast<HtmlAttribute*>(p);
        if ( names.contains(a->name()) )
            qDebug("HTML attribute is duplicated");
        else
            names.insert(a->name());
        p = p->nextSibling();
    }
}
